package Presentacion;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

import Dominio.Usuarios;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.LinkedList;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

public class VentanaRegistrarse extends JFrame {

	private JPanel contentPane;
	private JTextField txtCIF;
	private JPasswordField txtContrasena;	
	private LinkedList <Usuarios> listaUsuarios=new LinkedList<Usuarios>();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					VentanaRegistrarse frame = new VentanaRegistrarse();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public VentanaRegistrarse() {
		setTitle("Registro de Usuario");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 300, 200);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		final JPanel panelRegistro = new JPanel();
		contentPane.add(panelRegistro, BorderLayout.CENTER);
		GridBagLayout gbl_panelRegistro = new GridBagLayout();
		gbl_panelRegistro.columnWidths = new int[]{0, 0, 17, 82, 0, 0};
		gbl_panelRegistro.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
		gbl_panelRegistro.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_panelRegistro.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		panelRegistro.setLayout(gbl_panelRegistro);
		
		JLabel lblCif = new JLabel("CIF");
		GridBagConstraints gbc_lblCif = new GridBagConstraints();
		gbc_lblCif.anchor = GridBagConstraints.EAST;
		gbc_lblCif.insets = new Insets(0, 0, 5, 5);
		gbc_lblCif.gridx = 1;
		gbc_lblCif.gridy = 1;
		panelRegistro.add(lblCif, gbc_lblCif);
		
		txtCIF = new JTextField();
		GridBagConstraints gbc_txtCIF = new GridBagConstraints();
		gbc_txtCIF.gridwidth = 2;
		gbc_txtCIF.insets = new Insets(0, 0, 5, 5);
		gbc_txtCIF.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtCIF.gridx = 2;
		gbc_txtCIF.gridy = 1;
		panelRegistro.add(txtCIF, gbc_txtCIF);
		txtCIF.setColumns(10);
		
		JLabel lblContrasea = new JLabel("Contrase\u00F1a");
		GridBagConstraints gbc_lblContrasea = new GridBagConstraints();
		gbc_lblContrasea.anchor = GridBagConstraints.EAST;
		gbc_lblContrasea.insets = new Insets(0, 0, 5, 5);
		gbc_lblContrasea.gridx = 1;
		gbc_lblContrasea.gridy = 2;
		panelRegistro.add(lblContrasea, gbc_lblContrasea);
		
		txtContrasena = new JPasswordField();
		GridBagConstraints gbc_txtContrasena = new GridBagConstraints();
		gbc_txtContrasena.gridwidth = 2;
		gbc_txtContrasena.insets = new Insets(0, 0, 5, 5);
		gbc_txtContrasena.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtContrasena.gridx = 2;
		gbc_txtContrasena.gridy = 2;
		panelRegistro.add(txtContrasena, gbc_txtContrasena);
		
		JLabel lblTipo = new JLabel("Tipo");
		GridBagConstraints gbc_lblTipo = new GridBagConstraints();
		gbc_lblTipo.anchor = GridBagConstraints.EAST;
		gbc_lblTipo.insets = new Insets(0, 0, 5, 5);
		gbc_lblTipo.gridx = 1;
		gbc_lblTipo.gridy = 3;
		panelRegistro.add(lblTipo, gbc_lblTipo);
		final JComboBox txtTipo = new JComboBox();
		txtTipo.setModel(new DefaultComboBoxModel(new String[] {"", "Cliente", "Proveedor"}));
		GridBagConstraints gbc_txtTipo = new GridBagConstraints();
		gbc_txtTipo.gridwidth = 2;
		gbc_txtTipo.insets = new Insets(0, 0, 5, 5);
		gbc_txtTipo.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtTipo.gridx = 2;
		gbc_txtTipo.gridy = 3;
		panelRegistro.add(txtTipo, gbc_txtTipo);
		JButton btnAnadirU = new JButton("A\u00F1adir");
		GridBagConstraints gbc_btnAnadirU = new GridBagConstraints();
		gbc_btnAnadirU.gridwidth = 2;
		gbc_btnAnadirU.insets = new Insets(0, 0, 5, 5);
		gbc_btnAnadirU.gridx = 2;
		gbc_btnAnadirU.gridy = 4;
		panelRegistro.add(btnAnadirU, gbc_btnAnadirU);
		
		btnAnadirU.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent arg0) {
				String CIF="";
				String Contrasena="";
				String tipo="";
				CIF=txtCIF.getText();
				Contrasena=txtContrasena.getText();
				tipo=txtTipo.getSelectedItem().toString();
				listaUsuarios.add(new Usuarios(CIF,Contrasena,tipo));
				JOptionPane.showMessageDialog(panelRegistro,"Se ha almacenado el nuevo usuario en la base datos");
				txtCIF.setText("");
				txtContrasena.setText("");
				txtTipo.setSelectedIndex(0);
					
			}
		});
		
		
	}
	public LinkedList<Usuarios> listUsuarios(){
		return listaUsuarios;
	}


}
